package com.smm.controller;


import com.jn.sqlhelper.dialect.pagination.PagingResult;
import com.smm.common.Result;
import com.smm.entity.Collect;
import com.smm.service.CollectService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(value = "Collect相关", tags = "Collect")
@RequestMapping("collect")
public class CollectController {
    @Resource
    CollectService collectService;

    @PostMapping("/")
    public Result addCollect(Collect collect) {
        return Result.SUCCESS(collectService.addCollect(collect));
    }

    @DeleteMapping("/{id}")
    public Result deleteCollect(@PathVariable("id") Integer id) {
        return Result.SUCCESS(collectService.deleteCollect(id));
    }

    @GetMapping("/{tag}")
    public Result findCollect(@PathVariable("tag") String tag) {
        Collect collect = new Collect();
        collect.setTag(tag);
        return Result.SUCCESS(collectService.findColect(collect));
    }

    @PutMapping("/")
    public Result updateCollect(Collect collect) {
        return Result.SUCCESS(collectService.updateCollect(collect));
    }

    @GetMapping("/{pageSize}/{pageNumber}")
    public Result findCollectPage(Collect collect,
                                  @PathVariable("pageSize") Integer pageSize,
                                  @PathVariable("pageNumber") Integer pageNumber) {
        PagingResult collects = collectService.findCommentPage(collect, pageSize, pageNumber);

        return Result.SUCCESS(collects);
    }
}
